package com.xiliubit.cloudpicture.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiliubit.cloudpicture.api.aliyunai.model.CreateOutPaintingTaskResponse;
import com.xiliubit.cloudpicture.common.DeleteRequest;
import com.xiliubit.cloudpicture.model.dto.picture.*;
import com.xiliubit.cloudpicture.model.entity.Picture;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xiliubit.cloudpicture.model.entity.User;
import com.xiliubit.cloudpicture.model.vo.PictureVO;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* @author 86173
* @description 针对表【picture(图片)】的数据库操作Service
* @createDate 2025-07-30 15:17:32
*/
public interface PictureService extends IService<Picture> {
    /**
     * 上传图片
     * @param inputSource  图片源
     * @param pictureUploadRequest 前端传来的图片信息
     * @param user  用户
     * @return 图片信息
     */
    PictureVO uploadPicture(Object inputSource, PictureUploadRequest pictureUploadRequest, User user);

    /**
     * 转换图片至Vo对象
     * @param picture 图片
     * @param request  请求
     * @return 图片Vo信息
     */
    PictureVO getPictureVO(Picture picture, HttpServletRequest request);

    /**
     * 获取查询包装类
     * @param pictureQueryRequest 查询条件
     * @return 查询条件
     */
    QueryWrapper<Picture> getQueryWrapper(PictureQueryRequest pictureQueryRequest);

    /**
     * 获取分页查询结果进行VO转换
     * @param page 分页信息
     * @param request 请求
     * @return 图片Vo信息
     */
    Page<PictureVO> getPictureVOPage(Page<Picture> page, HttpServletRequest request);

    /**
     * 校验图片信息
     * @param picture 图片信息
     */
    void validPicture(Picture picture);

    /**
     * 图片审核
     * @param pictureReviewRequest 图片审核信息
     * @param loginUser 用户信息
     */
    void doPictureReview(PictureReviewRequest pictureReviewRequest, User loginUser);

    /**
     * 填充审核参数
     * @param picture 图片信息
     * @param loginUser 用户信息
     */
    void fillReviewParams(Picture picture, User loginUser);

    /**
     * 批量抓取和创建图片
     *
     * @param pictureUploadByBatchRequest
     * @param loginUser
     * @return 成功创建的图片数
     */
    Integer uploadPictureByBatch(
            PictureUploadByBatchRequest pictureUploadByBatchRequest,
            User loginUser
    );

    /**
     * 异步删除图片文件
     *
     * @param oldPicture  要删除的图片
     */
    @Async("asyncDeletePictureExecutor")
    void clearPictureFile(Picture oldPicture);

    /**
      检查图片权限

      @param picture   图片信息
     * @param loginUser 用户信息
     */
    void checkPictureAuth(Picture picture, User loginUser);

    /**
     * 删除图片
     *
     * @param deleteRequest 删除请求
     * @param request       请求
     * @return 是否成功
     */
    boolean deletePicture(DeleteRequest deleteRequest, HttpServletRequest request);

    /**
     * 以颜色搜图
     *
     * @param picColor  图片颜色
     * @param spaceId   空间id
     * @param loginUser 用户信息
     * @return 图片信息
     */
    List<PictureVO> searchPictureByColor(String picColor, Long spaceId, User loginUser);

    /**
     * 批量修改图片信息
     *
     * @param pictureEditByBatchRequest 图片信息
     * @param loginUser                 用户信息
     */
    void editPictureByBatch(PictureEditByBatchRequest pictureEditByBatchRequest, User loginUser);

    /**
     * 创建图片外绘任务
     *
     * @param createPictureOutPaintingTaskRequest 图片外绘任务请求参数
     * @param loginUser                           登录用户
     */
    CreateOutPaintingTaskResponse createPictureOutPaintingTask(CreatePictureOutPaintingTaskRequest createPictureOutPaintingTaskRequest, User loginUser);

    /**
     * 上传头像
     *
     * @return 头像Url
     */
    String uploadAvatar(MultipartFile multipartFile, User loginUser);
}
